package com.example.onlineeducation.utils

import android.R.id.text1
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.AbsoluteSizeSpan
import android.text.style.BackgroundColorSpan
import android.text.style.ForegroundColorSpan
import android.widget.TextView


/**
 * Creator: yc
 * Date: 2022/4/21 14:42
 * UseDes:
 */
object YcSpannable {
    @JvmStatic
    fun setText(tv: TextView, data1: String, data2: String, color2: Int) {
        val textSpanned1 = SpannableString(data1 + data2)
        textSpanned1.setSpan(ForegroundColorSpan(color2), data1.length, data1.length + data2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        tv.text = textSpanned1
    }

    @JvmStatic
    fun setTextError(tv: TextView, data1: String, data2: String, errorColor: Int,color2: Int) {
        val textSpanned1 = SpannableString(data1 + data2)
        textSpanned1.setSpan(ForegroundColorSpan(errorColor), 0, data1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        textSpanned1.setSpan(ForegroundColorSpan(color2), data1.length, data1.length + data2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        tv.text = textSpanned1
    }


    /*
    * 有小单位的text
    * size:px
    * */
    @JvmStatic
    fun setTextHasUnit(tv: TextView, data1: String, data2: String, size1: Int,size2: Int) {
        val textSpanned1 = SpannableString(data1 + data2)
        textSpanned1.setSpan(AbsoluteSizeSpan(size1), 0, data1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        textSpanned1.setSpan(AbsoluteSizeSpan(size2), data1.length, data1.length + data2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        tv.text = textSpanned1
    }
}